
export default app => {
  const { INTEGER } = app.Sequelize;
  // 角色与菜单关联表
  const RoleMenu = app.model.define('RoleMenu', {
    id: {
      primaryKey: true,
      type: INTEGER,
      autoIncrement: true,
      comment: '角色与菜单关联id',
    },
    roleId: {
      type: INTEGER,
      defaultValue: null,
      comment: '角色id',
    },
    menuId: {
      type: INTEGER,
      defaultValue: null,
      comment: '菜单id',
    },
    createTime: {
      type: INTEGER,
      defaultValue: null,
      comment: '创建时间',
    },
    updateTime: {
      type: INTEGER,
      defaultValue: null,
      comment: '更新时间',
    },
  },
  {
    tableName: 'role_menu',
    comment: '角色与菜单关联表',
    timestamps: false,
  },
  );
  // 角色与菜单关联表关联角色表
  RoleMenu.associate = function() {
    app.model.RoleMenu.belongsTo(app.model.Role, {
      foreignKey: 'roleId',
      targetKey: 'id',
      as: 'role',
    });
    // 角色与菜单关联表关联菜单表
    app.model.RoleMenu.belongsTo(app.model.Menu, {
      foreignKey: 'menuId',
      targetKey: 'id',
      as: 'menu',
    });
  };
  return RoleMenu;

};
